<template>
  <view class="systemPopup">
    <u-popup :show="internalSystemPopupShow" mode="center">
      <view class="popup">
        <!-- 这里是你的弹窗内容 -->
        <image
          class="systemPopupShow_icon"
          src="/static/img/index/systemPopupShow_icon.png"
          mode="scaleToFill"
        />
        <view class="info">
          <view class="title">打开消息通知</view>
          <view class="content"
            >开启后你可以第一时间接收精彩活动资讯、问答通知、最新法规库等重要内容</view
          >
          <view class="btn" @click="openSystem">去开启</view>
          <view class="msg">建议前往“系统设置”中开启</view>
        </view>

        <view class="close" @click="close">
          <u-icon color="#fff" name="close-circle" size="40"></u-icon>
        </view>
      </view>
    </u-popup>
  </view>
</template>

<script>
export default {
  name: "systemPopup",
  props: {
    // 这里是你的弹窗参数
    systemPopupShow: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      internalSystemPopupShow: this.systemPopupShow,
    };
  },
  watch: {
    //监听systemPopupShow
    systemPopupShow(val) {
      this.internalSystemPopupShow = val;
    },
  },
  created() {},
  mounted() {},
  methods: {
    close() {
      var currentTime = Date.now();
      // 获取上次安装的时间
      var lastInstallTime = uni.getStorageSync("installTime");
      uni.setStorageSync("openTime", currentTime);
      if (!lastInstallTime) {
        console.log("第一次安装");
        // 保存当前时间作为第一次安装时间
        uni.setStorageSync("installTime", currentTime);
      }
      uni.setStorageSync("notificationEnabled", false);
      console.log("关闭", uni.getStorageSync("openTime"));
      uni.setStorageSync("goSystemSettings", false);
      this.internalSystemPopupShow = false;
      this.$store.commit("SET_STATUS_INFORM", false);
    },
    openSystem() {
      uni.setStorageSync("goSystemSettings", true);
      let main = plus.android.runtimeMainActivity();
      let pkName = main.getPackageName();
      let uid = main.getApplicationInfo().plusGetAttribute("uid");
      let Intent = plus.android.importClass("android.content.Intent");
      let Build = plus.android.importClass("android.os.Build");
      let intent = "";
      console.log("Androd SDK_INT:" + Build.VERSION.SDK_INT);

      if (Build.VERSION.SDK_INT >= 26) {
        // android 8.0引导
        intent = new Intent("android.settings.APP_NOTIFICATION_SETTINGS");
        intent.putExtra("android.provider.extra.APP_PACKAGE", pkName);
      } else if (Build.VERSION.SDK_INT >= 21) {
        //android 5.0-7.0
        intent = new Intent("android.settings.APP_NOTIFICATION_SETTINGS");
        intent.putExtra("app_package", pkName);
        intent.putExtra("app_uid", uid);
      } else {
        //(<21)其他--跳转到该应用管理的详情页
        let Settings = plus.android.importClass("android.provider.Settings");
        let Uri = plus.android.importClass("android.net.Uri");
        intent = new Intent();
        intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        let uri = Uri.fromParts("package", main.getPackageName(), null);
        intent.setData(uri);
      }
      // 跳转
      main.startActivity(intent);
    },
  },
};
</script>

<style lang="scss" scoped>
.popup {
  z-index: 999;
  /* 这里是你的弹窗样式 */
  width: 580rpx;
  height: 724rpx;
  border-radius: 16rpx;
  background: #fff;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);

  .systemPopupShow_icon {
    width: 580rpx;
    height: 258rpx;
  }

  .info {
    display: flex;
    flex-direction: column;
    align-items: center;

    .title {
      margin-top: 53rpx;
      font-size: 40rpx;
      font-weight: 700;
      color: #333333;
      line-height: 58rpx;
    }

    .content {
      margin-top: 20rpx;
      max-width: 444rpx;
      font-size: 26rpx;
      font-family: Source Han Sans, Source Han Sans;
      color: #999999;
      line-height: 38rpx;
    }

    .btn {
      margin-top: 45rpx;
      width: 404rpx;
      height: 90rpx;
      background: #317cfe;
      border-radius: 128rpx;
      text-align: center;
      line-height: 90rpx;
      color: #fff;
      font-size: 32rpx;
    }

    .msg {
      margin-top: 28rpx;
      font-size: 26rpx;
      color: #4092ed;
      line-height: 38rpx;
    }
  }

  .close {
    position: absolute;
    bottom: -180rpx;
    left: 50%;
    transform: translateX(-50%);
  }
}
</style>
